import Vue from 'vue'
import VueRouter from 'vue-router'
import { scrollBehavior } from './scrollBehavior'
import { createRouterGuards } from './routerGuards'
import { basicRoutes } from './routes'

Vue.use(VueRouter)

/**
 * 解决跳转重复路由地址报错
 */
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

/**
 * routes路由结构说明
 *
 * path                     路由
 * name                     路由name
 * component                页面组件，可选layout枚举："@/enums/appEnum"
 * meta                     meta
 * meta.title               页面标题
 * meta.requireAuth         开启访问权限
 * meta.noKeepAlive         关闭KeepAlive
 * meta.affix               开启tabview模式下，固定显示项
 * meta.hideMenu            是否在菜单中隐藏
 * meta.icon                菜单icon
 * children                 子菜单，同父级
 */

const router = new VueRouter({
  mode: 'history',
  routes: basicRoutes,
  scrollBehavior: scrollBehavior
})

// 路由hook
createRouterGuards(router)

export default router
